package com.yty.newconsult.controller;

import com.yty.newconsult.common.Result;
import com.yty.newconsult.common.ResultGenerator;
import com.yty.newconsult.entity.QueryMessage;
import com.yty.newconsult.service.QueryHistoryService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (QueryHistory)表控制层
 *
 * @author makejava
 * @since 2025-04-08 19:30:28
 */
@RestController
@RequestMapping("history")
public class QueryHistoryController {
    /**
     * 服务对象
     */
    @Resource
    private QueryHistoryService queryHistoryService;



    @GetMapping("query")
    public Result queryByUserId(@RequestParam String userId){
        return ResultGenerator.genSuccessResult(queryHistoryService.queryByUserId(userId));
    }
    /**
     * 分页查询
     *
     * @param queryMessage 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<QueryMessage>> queryByPage(QueryMessage queryMessage, PageRequest pageRequest) {
        return ResponseEntity.ok(this.queryHistoryService.queryByPage(queryMessage, pageRequest));
    }



    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.queryHistoryService.deleteById(id));
    }

}

